package com.oxygen.pt.mapper;

import com.oxygen.pt.pojo.entity.TreatmentDetail;
import org.apache.ibatis.annotations.*;

@Mapper
public interface TreatmentDetailMapper {

    @Select("SELECT * FROM treatment_detail where patient_id = #{id}")
    TreatmentDetail getByPatientId(Long id);

    @Update("UPDATE treatment_detail " +
            "SET patient_id = #{patientId}, " +
            "completed_sessions = #{completedSessions}, " +
            "remaining_sessions = #{remainingSessions}, " +
            "total_sessions = #{totalSessions}, " +
            "last_treatment_date = #{lastTreatmentDate}, " +
            "updated_at = CURRENT_TIMESTAMP " +
            "WHERE id = #{id}")
    void updateTreatmentDetail(TreatmentDetail treatmentDetail);

    @Insert("INSERT INTO treatment_detail ( " +
            "patient_id, completed_sessions, remaining_sessions, " +
            "total_sessions, last_treatment_date " +
            ") VALUES ( " +
            "#{patientId}, #{completedSessions}, #{remainingSessions}, " +
            "#{totalSessions}, #{lastTreatmentDate, jdbcType=TIMESTAMP} " +
            ")")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insert(TreatmentDetail treatmentDetail);

}
